<?php
/**
 * @文件功能名称  : 配置中心模块
 * @Author      : yaoGrace
 * @Date        : 2021/12/11 19:31
 */
namespace phpGrace\models;
class menu extends  \graceModel
{
    public $tableName = "manager_menus";
    public $tableKey = "mid";

    public function getDataByControlAndMethod($controller,$method){
        return $this->m->where("controller = ? and method = ? ",array($controller,$method))->fetch();
    }

    // 通过pid 查询所有数据
    public function getlist($pid){
        return $this->m->where("pid = ? " ,array($pid))->order("ord asc")->fetchAll();
    }

    //查询所有非禁用的数据
    public function getMenuList(){
        $status = 0;
        return $this->m->where("status = ? ",array( $status )  )->fetchAll();
    }

    public function getlistwhere($where){
        return $this->m->order('ord asc')->where( $where." and ishidden = 0 and status = ? ",array(0))->fetchAll();
    }

    // 通过mid为pid的父级的数据
    public function getlistbyPid($pid){
        return $this->m->where("mid = ? " ,array($pid))->order("ord asc")->fetch();
    }

    // 查询一条数据 通过mid查询
    public function getlistByMidEqMid($mid){
        return $this->m->where("mid = ? ",array($mid))->order('ord asc')->fetch();
    }

    // 增加
    public function add($data){
        return $this->m->add($data);
    }

    // 编辑
    public function update($mid,$data)
    {
        return $this->m->where($this->tableKey." = ? ",array($mid))->update($data);
    }

    /**
     * 删除
     * @param $mid
     * @return  true / false
     */
    public function del($mid)
    {
        return $this->m->where($this->tableKey." = ? ",array($mid))->delete();
    }

}